﻿import QtQuick 2.15
import QtQuick.Controls 2.15

import "../view"
import "../test"

ApplicationWindow {
    width: 400
    height: 600
    visible: true
    title: "全局右键菜单列表示例"

    Column {
        anchors.fill: parent
        spacing: 10

        Row {
            spacing: 10
            padding: 10

            Button {
                text: "切换单选/多选"
                onClicked: selectableList.singleSelectionMode = !selectableList.singleSelectionMode
            }

            Button {
                text: "添加项目"
                onClicked: selectableList.addItem({"name": "项目 " + (listModel.count + 1)})
            }
        }

        SelectableListt {
            id: selectableList
            width: parent.width
            height: parent.height - 100
            singleSelectionMode: false

            // 自定义颜色
            normalColor: "#FFFFFF"
            hoverColor: "#F0F0F0"
            selectedColor: "#2196F3"
            selectedHoverColor: "#1976D2"

            model: ListModel {
                id: listModel
                ListElement { name: "项目 1"; selected: false }
                ListElement { name: "项目 2"; selected: false }
                ListElement { name: "项目 3"; selected: false }
            }

            onItemSelected: (index, selected) => {
                console.log("项目", index, selected ? "被选中" : "取消选中")
            }

            onRightClicked: (mouse) => {
                console.log("右键点击位置:", mouse.x, mouse.y)
            }
        }
    }
}
